/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Santiago Ontanon, Kinshuk Mishra
 												Neha Sugandh 
 												
Class							:				ResearchCondition
 
Function						: 				Provides a class for research condition
****************************************************************************/
package planninglanguage.conditions;

import org.jdom.Element;

import util.XMLWriter;
import base.WargusGameState;
import base.WargusPlayer;

public class ResearchCondition extends Condition {
	String m_research;
	int m_playerID;
	
	public ResearchCondition(String a_research,int a_playerID)
	{
		m_research = a_research;
		m_playerID = a_playerID;
	}
	public String toString(int tabs)
	{
		String n = super.toString(tabs);
		n = n + "Research is:" + m_research;
		return n;
		
	}
	
	public boolean compare(ResearchCondition c)
	{
		if(m_research.equals(c.m_research))
			return true;
		else
			return false;
	}
	
	public boolean test(WargusGameState a_gameState)
	{		
		System.out.println("ResearchCondition: test( " + m_research + ")");	

		WargusPlayer p = a_gameState.getPlayer(m_playerID);
		
		if (p!=null) {			
			if (p.getResearch().contains(m_research)) return true;
		}
		return false;		
	}
	
	public void writeXML(XMLWriter w) {
		w.tag("condition type=\""+this.getClass().getSimpleName()+"\"");
		{
			w.tag("research", m_research);
			w.tag("player-id", m_playerID);
		}
		w.tag("/condition");
	}
	
	protected static Condition loadConditionFromXML(Element e) {
		return new ResearchCondition(e.getChildText("research"),
				Integer.parseInt(e.getChildText("player-id")));
	}
}
